package com.mrx.java8.Annotation;

import org.junit.jupiter.api.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * @create 2018-12-03 14:22
 */

/**
 * 重复注解与类型注解
 */
public class TestAnnotation {

    @MyAnnotation(value = "Hello")
    @MyAnnotation(value = "World")
    public void show(@MyAnnotation("abc") String str){

    }

    // 重复注解
    @Test
    public void test1() throws Exception {
        Class<TestAnnotation> clazz = TestAnnotation.class;
        Method m1 = clazz.getMethod("show",String.class);
        MyAnnotation[] mas = m1.getAnnotationsByType(MyAnnotation.class);

        for (MyAnnotation myAnnotation : mas){
            System.out.println(myAnnotation.value());
        }

        // 获取参数的注解内容
        Annotation[][] aa =  m1.getParameterAnnotations();
        for (Annotation[] a : aa){
            for (Annotation b : a){
                System.out.println(((MyAnnotation)b).value());
            }
        }
    }

}
